package com.cxf.windex.rest;

import com.cxf.windex.base.constant.UserConstant;
import com.cxf.windex.base.rest.BaseRestController;
import com.cxf.windex.base.util.FileFilterTool;
import com.cxf.windex.base.util.ShorUrlUtil;
import com.cxf.windex.biz.JsContentsBiz;
import com.cxf.windex.entity.JsContents;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @program: business_needs
 * @description: 文件上传类
 * @author: chenxf
 * @create: 2018-10-17 10:52
 **/
@Slf4j
@Api(tags = {"通用 - 文件上传接口"})
@RestController
@RequestMapping("/user/file")
public class FileController extends BaseRestController<JsContentsBiz, JsContents> {
  Pattern p = Pattern.compile("<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>");
  @ApiOperation(value = "上传图片", notes = "上传图片")
  @PostMapping( "/upload")
  public Map upload(@RequestParam("file") MultipartFile file) {
    return baseBiz.upload(file, UserConstant.ARTICLE_TYPE);
  }

  @ApiOperation(value = "上传base64图片", notes = "上传base64图片")
  @ApiImplicitParams({
          @ApiImplicitParam(name = "fileType", value = "文件类型 如jpg,png", required = true, paramType = "query", dataType = "String"),
          @ApiImplicitParam(name = "base64", value = "base64文件", required = true, paramType = "query", dataType = "String")
  })
  @PostMapping( "/base64Upload")
  public Map Base64Upload(String fileType,String base64) {
    return baseBiz.base64Upload(fileType,base64);
  }


}
